import 'package:flutter/services.dart';
import 'package:flutter_bmflocation/src/private/bdmap_location_callback_handler.dart';
import 'package:flutter_bmflocation/src/private/bdmap_location_method_id.dart';

class BMFLocationChannelManager {
  // private constructor
  BMFLocationChannelManager._internal() {
    _locationChannel =
        const MethodChannel(BMFLocationConstants.kLocationChannelName);
    _geofenceChannel =
        const MethodChannel(BMFGeofenceConstants.kGeofenceChannelName);
    _callbackHandler = BMFLocationCallbackHandler();
    // 一个handler可以同时处理来自两个channel的回调
    _locationChannel.setMethodCallHandler(_callbackHandler.handlerMethod);
    _geofenceChannel.setMethodCallHandler(_callbackHandler.handlerMethod);
  }

  // singleton instance
  static final BMFLocationChannelManager _instance =
      BMFLocationChannelManager._internal();

  // factory constructor
  static BMFLocationChannelManager get instance => _instance;

  late MethodChannel _locationChannel;
  late MethodChannel _geofenceChannel;
  late BMFLocationCallbackHandler _callbackHandler;

  MethodChannel get locationChannel => _locationChannel;
  MethodChannel get geofenceChannel => _geofenceChannel;
  BMFLocationCallbackHandler get callbackHandler => _callbackHandler;
}
